package com.tobeface.wechat.message;

import com.google.common.base.Objects;

/**
 * @author loudyn
 */
public class WeChatMessageCredential {

    private final String signature;
    private final String timestamp;
    private final String nonce;
    private final String echostr;

    /**
     * @param builder
     */
    WeChatMessageCredential(Builder builder) {
        this.signature = builder.signature;
        this.timestamp = builder.timestamp;
        this.nonce = builder.nonce;
        this.echostr = builder.echostr;
    }

    public String getSignature() {
        return signature;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public String getNonce() {
        return nonce;
    }

    public String getEchostr() {
        return echostr;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        WeChatMessageCredential that = (WeChatMessageCredential) o;
        return Objects.equal(getSignature(), that.getSignature()) &&
                Objects.equal(getTimestamp(), that.getTimestamp()) &&
                Objects.equal(getNonce(), that.getNonce()) &&
                Objects.equal(getEchostr(), that.getEchostr());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getSignature(), getTimestamp(), getNonce(), getEchostr());
    }

    @Override
    public String toString() {
        return Objects.toStringHelper(this).add("signature",getSignature())
                                            .add("timestamp", getTimestamp())
                                            .add("nonce", getNonce())
                                            .add("echostr",getEchostr()).toString();
    }

    /**
     * @return
     */
    public static Builder newBuilder() {
        return new Builder();
    }

    /**
     *
     */
    public static class Builder {
        private String signature;
        private String timestamp;
        private String nonce;
        private String echostr;

        Builder() {
        }

        public Builder signature(String signature) {
            this.signature = signature;
            return this;
        }

        public Builder timestamp(String timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public Builder nonce(String nonce) {
            this.nonce = nonce;
            return this;
        }

        public Builder echostr(String echostr) {
            this.echostr = echostr;
            return this;
        }

        public WeChatMessageCredential build() {
            return new WeChatMessageCredential(this);
        }
    }
}
